package com.fz.controller;

import com.fz.entity.Shows;
import com.fz.entity.Situation;
import com.fz.entity.ZhuanChang;
import com.fz.mapper.WebZhuanChangMapper;
import com.fz.util.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by Z-C-Y on 2018-03-07.
 * zhuanchang.jsp====专场
 */
@Controller
public class WebZhuanChangController {
    @Autowired
    public WebZhuanChangMapper webZhuanChangMapper;

    @RequestMapping()
    public String zhuanChang(Model model, HttpServletRequest req) {
        /*得到页面专场的轮播图*/
        List<ZhuanChang> listZhuanChang = webZhuanChangMapper.queryZhuanChang();
        model.addAttribute("listZhuanChang",listZhuanChang);
        /*得到导航栏中的字段*/
        List<Situation> listSituation = webZhuanChangMapper.querySituation();
        model.addAttribute("listSituation",listSituation);
        /*分页*/
        /*实现分页并查询的功能*/
        int  pageNun1 = 1;
        if((req.getParameter("pageNun") != null) && !("".equals(req.getParameter("pageNun")))){
            pageNun1 = Integer.parseInt(req.getParameter("pageNun"));
        }
        //System.out.println("==获得当前是第几页==pageNun===="+req.getParameter("pageNun"));
        //每页显示的记录数
        int pageSize = 3;
        /*分页======查询数据库的数据的总数据*/
        List<Shows> list2 = webZhuanChangMapper.queryShows();
        model.addAttribute("list2Artist",list2);

        /*得到表中总条数*/
        int totalRecord = list2.size();

        //有了初始化数据，就可以创建PageBean对象了
        PageBean pbm = new PageBean(pageNun1, pageSize, totalRecord);

        model.addAttribute("pbm",pbm);
        //获取PageBeanManage对象中的startIndex;
        int startIndex = pbm.getStartIndex();

        //有了pageSize和startIndex，就可以拿到每页的数据
        List<Shows> dataNumber =  webZhuanChangMapper.queryDataShows(startIndex,pageSize);
        model.addAttribute("dataNumber",dataNumber);
        model.addAttribute("t","zhuanchang");
        return "/webpage/zhuanchang";
    }

}
